﻿using System;

using System.Collections.Generic;
using System.Text;

namespace RSSRadio.Model
{
    public interface ISubscriptionUpdateListener
    {
        void SubscriptionStateUpdated(String feedURL, FeedState oldState, FeedState newState);

        void SubscriptionEpisodeUpdated(String feedURL, String episodeURL, String episodePublishedDate, EpisodeState state);
        
        void SubscriptionDetailsUpdated(String feedURL);
    }

    public class SubscriptionUpdateListenerReplicatorImpl : BaseListenerReplicator<ISubscriptionUpdateListener>, ISubscriptionUpdateListener
    {
        #region ISubscriptionUpdateListener base implementation 
        public void SubscriptionStateUpdated(String feedURL, FeedState oldState, FeedState newState)
        {
            SubscriptionStateUpdatedImpl(feedURL, oldState, newState);
            foreach (ISubscriptionUpdateListener listener in Listeners)
            {
                listener.SubscriptionStateUpdated(feedURL,oldState,newState);
            }
        }

        public void SubscriptionEpisodeUpdated(String feedURL, String episodeURL, String episodePublishedDate, EpisodeState state)
        {
            SubscriptionEpisodeUpdatedImpl(feedURL, episodeURL, episodePublishedDate, state);
            foreach (ISubscriptionUpdateListener listener in Listeners)
            {
                listener.SubscriptionEpisodeUpdated(feedURL, episodeURL, episodePublishedDate, state);
            }
        }

        public void SubscriptionDetailsUpdated(String feedURL)
        {
            SubscriptionDetailsUpdatedImpl(feedURL);
            foreach (ISubscriptionUpdateListener listener in Listeners)
            {
                listener.SubscriptionDetailsUpdated(feedURL);
            }
        }
        #endregion

        #region ISubscriptionUpdateListener implmementations that can be overriden
        protected virtual void SubscriptionStateUpdatedImpl(String feedURL, FeedState oldState, FeedState newState)
        {
        }

        protected virtual void SubscriptionEpisodeUpdatedImpl(String feedURL, String episodeURL, String episodePublishedDate, EpisodeState state)
        {
        }

        protected virtual void SubscriptionDetailsUpdatedImpl(String feedURL)
        {
        }
        #endregion
    }
}
